<template>
  <section>
    <el-table :data="waitSignList" border highlight-current-row v-loading="listLoading" style="width: 100%;">
      <el-table-column header-align="center" align="center" type="index" width="50"></el-table-column>
      <el-table-column header-align="center" prop="docName" label="文件名" min-width="120"></el-table-column>
      <el-table-column header-align="center" prop="realName" label="创建者" min-width="100"></el-table-column>
      <el-table-column header-align="center" prop="remarks" label="备注" min-width="100"></el-table-column>
      <el-table-column header-align="center" prop="createTime" label="创建日期" min-width="120"></el-table-column>
      <el-table-column header-align="center" prop="state" label="状态" min-width="150"></el-table-column>
      <el-table-column header-align="center" label="操作" min-width="250">
        <template slot-scope="scope">
          <el-button size="mini" icon="el-icon-edit-outline" round type="primary" @click="sign(scope.row)">签名
          </el-button>
          <el-button size="mini" icon="el-icon-message" round @click="send(scope.row)">发回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-col :span="24" class="toolbar">
      <el-pagination layout="total, sizes, prev, pager, next, jumper"
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :page-sizes="pageSizes"
                     :page-size="pageSize" :total="total" style="float:right;">
      </el-pagination>
    </el-col>
  </section>
</template>

<script>
  import {getNowTime} from "../../utils";
  import API from '@/api'

  export default {
    name: "wait-sign",

    data() {
      return {
        waitSignList: [],
        listLoading: false,
        user: {},
        creatoruser: [],

        //分页参数
        pageSizes: this.CONSTANT.PAGE_SIZES,
        pageSize: this.CONSTANT.PAGE_SIZE,
        total: 0,
        pageIndex: 1, //页码
      }
    },
    methods: {
      init(data) {
        // this.listLoading = true;
        // this.myFileList = data;
        // console.log(this.myFileList);
        // this.listLoading = false;
      },
      handleSizeChange(value) {
        this.pageSize = value;
        this.getFileList();
      },
      handleCurrentChange(value) {
        this.pageIndex = value;
        this.getFileList();
      },
      getUserInfo() {
        API.user.info().then(res => {
          this.user = res.data.user;
          this.getFileList();
        }).catch(error => {
          console.log(error);
        });
      },
      getFileList() {
        let params = {
          page: this.pageIndex,
          limit: this.pageSize,
          holderId: this.user.id,
        };
        API.signDoc.lists(params).then(res => {
          if (!res.data.code) {
            this.waitSignList = res.data.page.list;
            this.getCreateUserInfo();
            this.total = res.data.page.totalCount;
          } else {
            this.$message.error(res.data.msg);
          }

        }).catch(error => {
          console.log(error);
          this.$message.error(error);
        });
      },
      getCreateUserInfo() {
        for (let i = 0; i < this.waitSignList.length; i++) {
          let id = this.waitSignList[i].creatorId;
          API.user.FindByid(id).then(res => {
            this.$set(this.waitSignList[i], 'realName', res.data.user.realName);
          }).catch(error => {
            console.log(error);
          })
        }
      },
      sign(val) {
        this.$router.push({path: '/signPDF', query: {fileimfor: val}});
      },
      send(val) {
        let para={
          id:val.id,
          holderId:val.creatorId,
        };
        API.signDoc.modify(para).then(res=>{
          this.$message.success('发回成功！');
        }).catch(error=>{
          console.log(error);
        });
        this.getFileList();
      },
    },
    activated() {
      this.getUserInfo();
      console.log(this.user);
    }
  }
</script>

<style scoped>

</style>
